//判断是否为空，0或null
function isNull0(data, txt) {
    var val = '';
    if (data == 0 || data == null || data == '' || data == '-') {
        val = '-';
    } else {
        if(txt == undefined || txt == 0 || txt == null || txt == ''){
            val = data;
        }else{
            val = data + txt;
        }
    }
    return val;
};

//判断美元价钱信息是否为0或null
function isNull0_USD(data, txt) {
    var val = '';
    if (data == null || data == 0 || data == '$0' || data == '$-' || data == '-') {
        val = '-';
    } else {
        if (txt == undefined || txt == '') {
            val = accounting.formatMoney(data, "$ ", 0);
        } else {
            val = accounting.formatMoney(data, "$ ", 0) + txt;
        }
    }
    return val;
};

//判断RMB价钱信息是否为0或null
function isNull0_RMB(data, txt) {
    var val = '';
    if (data == null || data == 0 || data == '$0' || data == '$-' || data == '-') {
        val = '-';
    } else {
        if (txt == undefined || txt == '') {
            val = accounting.formatMoney(parseInt(data * 6.3239), "约¥ ", 0);
        } else {
            val = accounting.formatMoney(parseInt(data * 6.3239), "约¥ ", 0) + txt;
        }
    }
    return val;
};

//判断平方英尺是否为0或null
function isNull0_sqft(data, txt) {
    var val = '';
    if (data == 0 || data == null || data == '' || data == '-') {
        val = '-';
    } else {
        val = data +'平方英尺';
    }
    return val;
};

//判断平方米是否为0或null
function isNull0_sqmt(data, txt) {
    var val = '';
    if (data == 0 || data == null || data == '' || data == '-') {
        val = '-';
    } else {
        val ='约'+ parseInt(data * 0.0929) +'平米';
    }
    return val;
};

// 时间戳格式化年月日时分
function dateFormat(data) {
    var val = '';
    if (data == 0 || data == null || data == '' || data == '-') {
        val = '-';
    } else {
        var now = new Date(data);
        var y = now.getFullYear();
        var m = now.getMonth() + 1;
        var d = now.getDate();
        var h = now.getHours();
        var min = now.getMinutes();
        val = y + "年" + todub(m) + "月" + todub(d) + "日 " + todub(h) + "时" + todub(min) + '分';
    }
    return val;
}
function todub(n){
    return n>=10 ? ''+n : '0'+n;
}

// 时间戳格式化年月
function dateFormat_yearMonth(data) {
    var val = '';
    if (data == 0 || data == null || data == '' || data == '-') {
        val = '-';
    } else {
        var now = new Date(data);
        var y = now.getFullYear();
        var m = now.getMonth() + 1;
        val = y +"-"+ todub(m);
    }
    return val;
}

//判断销售状态——基本信息和周边房源公用
function status(data) {
    var val = '';
    if (data == 'Active') {
        val = '<span style="color: red">热卖中</span>';
    } else if (data == 'Sold') {
        val = '<span style="color: red">已售出</span>';
    } else if (data == null || data == '') {
        val = '-';
    }
    return val;
}

//判断学校类型
function school_type(data) {
    var val = '';
    if(data == 'Public'){
        val = '公立';
    }else if(data == 'Private'){
        val = '私立';
    }else if(data == 'Charter'){
        val = '特许';
    }
    return val;
}

var houseTypeItem = [{"id":1,"name":"SFR","explain":"独栋别墅","icon":null,"remark":null},{"id":2,"name":"TownHouse","explain":"联排别墅","icon":null,"remark":null},{"id":3,"name":"Condo","explain":"公寓","icon":null,"remark":null},{"id":4,"name":"Co-op","explain":"共有公寓","icon":null,"remark":null},{"id":5,"name":"Multi","explain":"多单元公寓","icon":null,"remark":null},{"id":6,"name":"Land","explain":"土地","icon":null,"remark":null},{"id":7,"name":"Other","explain":"其他","icon":null,"remark":null}]
//房源类型翻译
function houseTypeTranslation(value){
    var val = '';
    houseTypeItem.forEach(function(i) {
        if(value == i.name){
            val = i.explain;
        }
    });
    return val;
};

//计算随机数
function randomNumber (m, n){
    var randomNum = Math.floor(Math.random() * (m - n) + n);
    return randomNum;
}

//计算随机颜色（RGB绿色范围）
function randomGreenColor (){
    var r = this.randomNumber(1, 100);
    var g = this.randomNumber(130, 255);
    return 'rgb('+ r +', '+ g +', 0)';
}

//$.isEmptyObject判断是否是空数组，返回true则表示无数据，false就是有数据，原理是for循环判断的，所以只能用于可枚举的对象，比如数组
//----------------------------房源图片----------------------------
function houseImgFN(res) {
    if(!$.isEmptyObject(res)){
        $('#housePhoto-box').show();
    }else{
        $('#housePhoto-box').hide();
    }
}

//----------------------------基本信息----------------------------
function basicInfoFN(res) {
    if(!$.isEmptyObject(res)){
        $('#houseDetails-box').show();
        var str = '';
        res.forEach(function(i) {
            str += '<aside class="col-lg-6 col-md-6 col-sm-6 col-xs-6">'+
                '<div>'+ i.key +'</div>'+
                '<div>'+ isPrice(i.key, i.value) +'</div>'+
                '</aside>';
        });
        $('#houseDetails-content').append(str);

    }else{
        $('#houseDetails-box').hide();
    }
}

//判断要翻译的字段
function isPrice (key, value) {
    var val = '';
    if(key == '价格' || key == '均价' || key == '预估月租' || key == '物业费'){
        val = value != '-' ? isNull0_USD(value) +'（'+ isNull0_RMB(value) +'）' : '-';
    }else if(key == '房产税'){
        val = value != '-' ? value.split(':')[0] +'年缴纳$'+ value.split(':')[1] : '-';
    }else if(key == '房屋面积'){
        val = isNull0(value, '平方英尺')
    }else if( key == '占地面积'){
        val = isNull0(value, '英亩')
    }else if( key == '房屋类型'){
        val = houseTypeTranslation(value)
    }else{
        val = isNull0(value)
    }
    return val;
}

//----------------------------房源特征----------------------------
function characteristicsInfoFN(res) {
    if(!$.isEmptyObject(res)){
        $('#characteristicsInfo-box').show();
    }else{
        $('#characteristicsInfo-box').hide();
    }
}

//----------------------------学校----------------------------
function schoolFN(res){
    // 小学
    if(!$.isEmptyObject(res.elementary)){
        $('#elementarySchools').show();
    }else{
        $('#elementarySchools').hide();
    }

    // 初中
    if(!$.isEmptyObject(res.middle)){
        $('#middleSchools').show();
    }else{
        $('#middleSchools').hide();
    }

    // 高中
    if(!$.isEmptyObject(res.high)){
        $('#highSchools').show();
    }else{
        $('#highSchools').hide();
    }
}

// 图表配置——公共最大值最小值——美元价钱缩写K、M
var markPoint_USD_KM = {
    data: [
        {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#f44336'}},
        {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#03a9f4'}}
    ],
    label:{
        formatter:function(param){
            var KM = '';
            if(param.value.toString().length >= 7){
                KM = (param.value/1000000).toFixed(1) +'M'
            }else{
                KM = Math.round(param.value/1000) +'k'
            }
            return '$'+ KM;
        }
    }
};
// 图表配置——公共最大值最小值——美元价钱
var markPoint_USD = {
    data: [
        {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#f44336'}},
        {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#03a9f4'}}
    ],
    label:{
        formatter:function(param){
            return accounting.formatMoney(param.value, "$", 0);
        }
    }
};
// 图表配置——公共最大值最小值——美元价钱小数点后两位
var markPoint_USD_decimalPoint2 = {
    data: [
        {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#f44336'}},
        {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#03a9f4'}}
    ],
    label:{
        formatter:function(param){
            return accounting.formatMoney(param.value, "$", 2);
        }
    }
};

//y轴的刻度标签的内容格式化——美元缩写K和M
var yAxis_axisLabel_formatter_KM = function(value){
    var KM = '';
    if(value.toString().length >= 7){
        KM = (value/1000000).toFixed(1) +'M'
    }else{
        KM = Math.round(value/1000) +'k'
    }
    return '$'+ KM;
};
//y轴的刻度标签的内容格式化——美元每平方英尺+小数点后两位
var yAxis_axisLabel_formatter_Sqft = function(value){
    return accounting.formatMoney(value, "$", 2);
};

//柱状图的柱子上边显示文字标签——展示美元价钱
var bar_charts_series_label_USD = {
    show: true,
    position: 'top',
    formatter:function(param){
        return accounting.formatMoney(param.value, "$", 0);
    },
    offset: [0, -5],
    textStyle:{
        fontSize: 16,
        color: '#000',
        fontWeight: 'bold'
    }
}
//柱状图的柱子的图表标线
var bar_charts_series_markLine = {
    label:{
        show:false
    },
    lineStyle: {
        type: 'dashed'
    },
    data : [
        [{type : 'min'}, {type : 'max'}]
    ]
};

//----------------------------此房源价格与附近均价对比——此房源每平方英尺价格与附近均价对比——此房源明年房价预测——本区域明年均价预测——柱状图——公共配置方法----------------------------
function houseData_bar_charts(e, xAxisData, seriesData){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }
    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        xAxis: {
            data: xAxisData,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                show: false,
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [{
            type: 'bar',
            barWidth: '40',
            label: bar_charts_series_label_USD,
            data: seriesData,
            markLine: bar_charts_series_markLine,
        }],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------%大数据量面积折线图——公共配置方法----------------------------
function Large_scale_area_charts(e, data, isMultiply100){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }

    //提取出value有值的数据，为''或0的剔除掉
    var dateList = [];
    var valueList = [];
    data.forEach(function(item){
        if(item.value && item.value != 0.00 && item.value != "NA"){
            dateList.push(item.time);
            if(isMultiply100){
                valueList.push(accounting.formatMoney(item.value * 100, "", 2));
            }else{
                valueList.push(accounting.formatMoney(item.value, "", 2));
            }
        }
    });
    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '30',
                fontSize: 12
            },
            //坐标轴轴线相关设置
            axisLine:{
                show: false,
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            boundaryGap: [0, '100%'],
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: '{value}%'
            },
            //坐标轴轴线相关设置
            axisLine:{
                show: false,
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [{
            type:'line',
            data: valueList,
            smooth: true,
            showSymbol: false,
            lineStyle: {
                width: 2
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(130, 223, 194, 0.2)'
                }, {
                    offset: 1,
                    color: 'rgba(130, 223, 194, 1)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            },
            itemStyle: {
                color: '#82dfc2',
                borderWidth: 2,
            },
            markPoint: {
                data: [
                    {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#f44336'}},
                    {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#03a9f4'}}
                ],
                label:{
                    formatter: function (param) {
                        return accounting.formatMoney(param.value, "", 2) +'%';
                    }
                }
            },
        }]
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}



//----------------------------本区域1~5居室户型的房价变化走势——折线图----------------------------
function get_one_five_beds(all1beds, all2beds, all3beds, all4beds, all5beds){
    var myChart = echarts.getInstanceByDom(document.getElementById('one-five-beds-housePrice-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('one-five-beds-housePrice-chart'));
    }
    //取出1~5居室数据里的时间
    var dateArr = [];
    if(all1beds.length > 0){
        dateArr = all1beds;
    }else{
        if(all2beds.length > 0){
            dateArr = all2beds
        }else{
            if(all3beds.length > 0){
                dateArr = all3beds
            }else{
                if(all4beds.length > 0){
                    dateArr = all4beds
                }else{
                    if(all5beds.length > 0){
                        dateArr = all5beds
                    }else{
                        dateArr = [];
                    }
                }
            }
        }
    }
    var dateList = all5beds.map(function (item) {
        return item['time'];
    });
    var all1bedsList = all1beds.map(function (item) {
        return item['value'];
    });
    var all2bedsList = all2beds.map(function (item) {
        return item['value'];
    });
    var all3bedsList = all3beds.map(function (item) {
        return item['value'];
    });
    var all4bedsList = all4beds.map(function (item) {
        return item['value'];
    });
    var all5bedsList = all5beds.map(function (item) {
        return item['value'];
    });

    // console.log(all1beds, all2beds, all3beds, all4beds, all5beds)

    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data:['一居室', '二居室', '三居室', '四居室', '五居及以上'],
            top: 30,
        },
        xAxis:  {
            type: 'category',
            boundaryGap: true,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: [{
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: function (value) {
                    var KM = '';
                    if(value.toString().length >= 7){
                        KM = (value/1000000).toFixed(1) +'M'
                    }else{
                        KM = Math.round(value/1000) +'k'
                    }
                    return '$'+ KM;
                },
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
            min: function(value) {
                return value.min;
            },
            max: function(value) {
                return value.max;
            }
        }],
        series: [
            {
                name: '一居室',
                type: 'line',
                smooth: true,
                showSymbol: false,
                data: all1bedsList,
                markPoint: markPoint_USD,
                connectNulls: true,
            },
            {
                name: '二居室',
                type: 'line',
                smooth: true,
                showSymbol: false,
                data: all2bedsList,
                markPoint: markPoint_USD,
                connectNulls: true,
            },
            {
                name: '三居室',
                type: 'line',
                smooth: true,
                showSymbol: false,
                data: all3bedsList,
                markPoint: markPoint_USD,
                connectNulls: true,
            },
            {
                name: '四居室',
                type: 'line',
                smooth: true,
                showSymbol: false,
                data: all4bedsList,
                markPoint: markPoint_USD,
                connectNulls: true,
            },
            {
                name: '五居及以上',
                type: 'line',
                smooth: true,
                showSymbol: false,
                data: all5bedsList,
                markPoint: markPoint_USD,
                connectNulls: true,
            }
        ],
        color: ['#40c3f9', '#ffbf53', '#fe5960', '#00bc7b', '#f963a0'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------独栋别墅与产权公寓的房价变化对比——折线图----------------------------
function get_SFR_Condo(CondoData, SFRData, legendData){
    console.log(legendData)
    var myChart = echarts.getInstanceByDom(document.getElementById('SFR-Condo-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('SFR-Condo-chart'));
    }
    //哪个数据数组有值，就取出对应的时间轴
    var dateList = [];
    if(CondoData.length > 0){
        dateList = CondoData.map(function (item) {
            return item['time'];
        });
    }else{
        if(SFRData.length > 0){
            dateList = SFRData.map(function (item) {
                return item['time'];
            });
        }
    }
    var CondoData = CondoData.map(function (item) {
        return item['value'];
    });
    var SFRData = SFRData.map(function (item) {
        return item['value'];
    });
    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legendData,
            top: 30,
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: function (value) {
                    var KM = '';
                    if(value.toString().length >= 7){
                        KM = (value/1000000).toFixed(1) +'M'
                    }else{
                        KM = Math.round(value/1000) +'k'
                    }
                    return '$'+ KM;
                },
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: legendData[0],
                type: 'line',
                data: SFRData,
                markPoint: markPoint_USD,
                showSymbol: false,
            },
            {
                name: legendData[1],
                type: 'line',
                data: CondoData,
                markPoint: markPoint_USD,
                showSymbol: false,
            },
        ],
        color: ['#40c3f9', '#ffbf53'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------本区域房价/租金关系——折线图----------------------------
function get_price_rent_rewards(prices, rents, rewards, legendData){
    var myChart = echarts.getInstanceByDom(document.getElementById('price-rent-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('price-rent-chart'));
    }
    //哪个数据数组有值，就取出对应的时间轴
    var dateList = [];
    if(prices.length > 0){
        dateList = prices.map(function (item) {
            return item['time'];
        });
    }else{
        if(rents.length > 0){
            dateList = rents.map(function (item) {
                return item['time'];
            });
        }else{
            if(rewards.length > 0){
                dateList = rewards.map(function (item) {
                    return item['time'];
                });
            }
        }
    }
    var pricesList = prices.map(function (item) {
        return item['value'];
    });
    var rentsList = rents.map(function (item) {
        return item['value'];
    });
    var rewardsList = rewards.map(function (item) {
        return accounting.formatMoney(item['value'], "", 2);
    });
    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            data: legendData,
            top: 30,
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: [
            {
                name: legendData[0],
                position: 'left',
                type: 'value',
                //分隔线的相关设置
                splitLine: {
                    lineStyle:{
                        color: '#f1f1f1'
                    }
                },
                //坐标轴刻度标签的相关设置
                axisLabel: {
                    color: '#969696',
                    formatter: function (value) {
                        var KM = '';
                        if(value.toString().length >= 7){
                            KM = (value/1000000).toFixed(1) +'M'
                        }else{
                            KM = Math.round(value/1000) +'k'
                        }
                        return '$'+ KM;
                    },
                },
                //坐标轴轴线相关设置
                axisLine:{
                    lineStyle:{
                        color: '#969696'
                    }
                },
                //坐标轴刻度相关设置
                axisTick:{
                    show: false,
                },
                min: function(value) {
                    return value.min - value.min * 0.2;
                },
                max: function(value) {
                    return value.max + value.max * 0.2;
                }
            },
            {
                name: legendData[1],
                type: 'value',
                position: 'right',
                //分隔线的相关设置
                splitLine: {
                    lineStyle:{
                        color: '#f1f1f1'
                    }
                },
                //坐标轴刻度标签的相关设置
                axisLabel: {
                    color: '#969696',
                    formatter: function (value) {
                        var KM = Math.round(value / 1000) + 'k';
                        return '$'+ KM;
                    }
                },
                //坐标轴轴线相关设置
                axisLine:{
                    lineStyle:{
                        color: '#969696'
                    }
                },
                //坐标轴刻度相关设置
                axisTick:{
                    show: false,
                },
                min: function(value) {
                    return value.min - value.min * 0.2;
                },
                max: function(value) {
                    return value.max + value.max * 0.2;
                }
            },
            {
                name: legendData[2],
                type: 'value',
                position: 'right',
                offset: 40,
                //分隔线的相关设置
                splitLine: {
                    lineStyle:{
                        color: '#f1f1f1'
                    }
                },
                //坐标轴刻度标签的相关设置
                axisLabel: {
                    color: '#969696',
                    formatter: function (value) {
                        return value + '%';
                    }
                },
                //坐标轴轴线相关设置
                axisLine:{
                    lineStyle:{
                        color: '#969696'
                    }
                },
                //坐标轴刻度相关设置
                axisTick:{
                    // show: false,
                },
                min: function(value) {
                    return value.min - value.min * 0.2;
                },
                max: function(value) {
                    return value.max + value.max * 0.2;
                }
            }
        ],
        series: [
            {
                name: legendData[0],
                type: 'line',
                smooth: true,
                data: pricesList,
                markPoint: markPoint_USD,
                showSymbol: false,
            },
            {
                name: legendData[1],
                type: 'line',
                smooth: true,
                yAxisIndex:1,
                data: rentsList,
                markPoint: markPoint_USD,
                showSymbol: false,
            },
            {
                name: legendData[2],
                type: 'line',
                smooth: true,
                showSymbol: false,
                yAxisIndex: 2,
                data: rewardsList,
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#00bc7b'}},
                        {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#00bc7b'}}
                    ],
                    label:{
                        formatter:function(param){
                            return (param.value).toFixed(1) +'%';
                        }
                    }
                },
            }
        ],
        color: ['#40c3f9', '#ffbf53', '#00bc7b'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------本州与全美房价变化对比——折线图----------------------------
function get_state_US_price(states, US, legendData){
    var myChart = echarts.getInstanceByDom(document.getElementById('state-US-price-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('state-US-price-chart'));
    }
    //哪个数据数组有值，就取出对应的时间轴
    var dateList = [];
    if(states.length > 0){
        dateList = states.map(function (item) {
            return item['time'];
        });
    }else{
        if(US.length > 0){
            dateList = US.map(function (item) {
                return item['time'];
            });
        }
    }
    var statesList = states.map(function (item) {
        return item['value'];
    });
    var USList = US.map(function (item) {
        return item['value'];
    });
    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legendData,
            top: 30,
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: function (value) {
                    var KM = '';
                    if(value.toString().length >= 7){
                        KM = (value/1000000).toFixed(1) +'M'
                    }else{
                        KM = Math.round(value/1000) +'k'
                    }
                    return '$'+ KM;
                },
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: legendData[0],
                type: 'line',
                data: statesList,
                markPoint: markPoint_USD_KM,
                showSymbol: false,
            },
            {
                name: legendData[1],
                type: 'line',
                data: USList,
                markPoint: markPoint_USD_KM,
                showSymbol: false,
            }
        ],
        color: ['#40c3f9', '#ffbf53'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}


//----------------------------HJ数据——柱状图——公共配置方法----------------------------
function HJData_bar_charts(e, titleText, xAxisData, seriesData, seriesLabel, color){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }
    var option = {
        animation: false,
        title: {
            text: titleText,
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        xAxis: {
            data: xAxisData,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '15',
                fontSize: 12
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [{
            type: 'bar',
            barWidth: '40',
            label: seriesLabel,
            data: seriesData,
        }],
        color: color
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------HJ数据——饼图——公共配置方法----------------------------
function HJData_pie_charts(e, titleText, seriesData, seriesLabel, color){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }
    var option = {
        animation: false,
        title: {
            text: titleText,
            left: 'center'
        },
        tooltip : {
            trigger: 'item',
        },
        series : [{
            type: 'pie',
            radius :  ['23%', '53%'],//圆的内外半径
            data: seriesData,
            label: seriesLabel
        }],
        color: color
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------hj数据——天气指数——平均最高温和最低温——折线图----------------------------
function averageHighLow_charts(titleName, legendData, xAxisData, jan, apr, jul, oct, annual){
    var myChart = echarts.getInstanceByDom(document.getElementById('averageHighLow-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('averageHighLow-chart'));
    }

    var highList = [];//平均最高温数据
    var lowList = [];//平均最低温数据

    // 处理一月、四月、七月、十月、全年的json数据，得出平均最高温和最低温数组
    highList.push(jan['high'], apr['high'], jul['high'], oct['high'], annual['high']);
    lowList.push(jan['low'], apr['low'], jul['low'], oct['low'], annual['low']);
    // console.log(highList, lowList);

    var markPoint = {
        data: [
            {type: 'max', name: '最大值', symbolSize: 65, itemStyle:{ color: '#f44336'}},
            {type: 'min', name: '最小值', symbolSize: 65, itemStyle:{ color: '#03a9f4'}}
        ],
        label:{
            formatter: function(param){
                return param.value +'°F';
            }
        }
    };

    var option = {
        animation: false,
        title: {
            text: titleName,
            left: 'center',
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legendData,
            top: 30,
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: xAxisData,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: '{value} °F'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: legendData[0],
                type: 'line',
                data: highList,
                markPoint: markPoint,
            },
            {
                name: legendData[1],
                type: 'line',
                data: lowList,
                markPoint: markPoint,
            },
        ],
        color: ['#40c3f9', '#ffbf53'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------zil数据图表——折线图——公共配置方法----------------------------
function zilData_line_charts(e, data, is_yAxis_axisLabel_formatter, is_markPoint, color){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }
    //提取出value有值的数据，为''或0的剔除掉
    var dateList = [];
    var valueList = [];
    data.forEach(function(item){
        if(item.value){
            dateList.push(item.time);
            valueList.push(item.value);
        }
    });

    //判断y轴的刻度标签的内容格式化——展示美元缩写K和M还是每平方英尺+小数点后两位
    var line_yAxis_axisLabel_formatter;
    if(is_yAxis_axisLabel_formatter == 'KM'){
        line_yAxis_axisLabel_formatter = yAxis_axisLabel_formatter_KM
    }else if(is_yAxis_axisLabel_formatter == 'Sqft'){
        line_yAxis_axisLabel_formatter = yAxis_axisLabel_formatter_Sqft
    }

    //判断柱状图的柱子上边显示文字标签——展示美元价钱还是价钱的小数点后两位（通常用于每平方英尺的图表）
    var line_markPoint;
    if(is_markPoint == '0'){
        line_markPoint = markPoint_USD
    }else if(is_markPoint == '2'){
        line_markPoint = markPoint_USD_decimalPoint2
    }

    var option = {
        animation: false,
        tooltip: {
            trigger: 'axis',
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45'
            },
            //坐标轴轴线相关设置
            axisLine:{
                show: false,
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: line_yAxis_axisLabel_formatter,
            },
            //坐标轴轴线相关设置
            axisLine:{
                show: false,
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [{
            type: 'line',
            data: valueList,
            smooth: true,
            showSymbol: false,
            lineStyle: {
                width: 2
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(246, 253, 251, 1)'
                }, {
                    offset: 0.8,
                    color: 'rgba(246, 253, 251, 1)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
            },
            itemStyle: {
                color: '#82dfc2',
                borderWidth: 2,
            },
            markPoint: line_markPoint
        }],
        color: color
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------zil数据图表——柱状图——公共配置方法----------------------------
function zilData_bar_charts(e, titleText, legendText, data, markPoint, color){
    var myChart = echarts.getInstanceByDom(document.getElementById(e));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById(e));
    }
    //提取出value有值的数据，为''或0的剔除掉
    var dateList = [];
    var valueList = [];
    data.forEach(function(item){
        if(item.value){
            dateList.push(item.time);
            valueList.push(Math.round(item.value));
        }
    });

    var option = {
        animation: false,
        title: {
            text: titleText,
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            data: legendText,
            top: 30,
        },
        xAxis: {
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45',
                fontSize: 12
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: legendText,
                type: 'bar',
                data: valueList,
                barGap: 0,
                label: {
                    show: true,
                },
                markPoint: markPoint
            }
        ],
        color: color
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

//----------------------------zil数据图表——存量房数字及高中低价位房产分布比例——存量房数字——柱状图——公共配置方法----------------------------
function InventoryMeasure_Metro_charts(data){
    var myChart = echarts.getInstanceByDom(document.getElementById('InventoryMeasure_Metro-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('InventoryMeasure_Metro-chart'));
    }
    //取出数据里的时间
    var dateList = [];
    if(data.bottom != null){
        dateList = data.bottom.map(function(item){
            return item.time;
        });
    }else{
        if(data.middle != null){
            dateList = data.middle.map(function(item){
                return item.time;
            });
        }else{
            if(data.top != null){
                dateList = data.top.map(function(item){
                    return item.time;
                });
            }
        }
    }

    //高价位
    var top_valueList = null;
    if(data.top != null){
        top_valueList = data.top.map(function(item){
            return Math.round(item['value'] );
        });
    }
    //中价位
    var middle_valueList = null;
    if(data.middle != null){
        middle_valueList = data.middle.map(function(item){
            return Math.round(item['value']);
        });
    }
    //低价位
    var bottom_valueList = null;
    if(data.bottom != null) {
        bottom_valueList = data.bottom.map(function(item){
            return Math.round(item['value']);
        });
    }

    var option = {
        animation: false,
        title: {
            text: '存量房数字（单位：套）',
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            data: ['高价位', '中价位', '低价位'],
            top: 30,
        },
        xAxis: {
            type: 'category',
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45',
                fontSize: 12
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: '高价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                data: top_valueList
            },
            {
                name: '中价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                data: middle_valueList
            },
            {
                name: '低价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                data: bottom_valueList
            }
        ],
        color: ['#40c3f9', '#ffbf53', '#fe5960'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}


//----------------------------zil数据图表——存量房数字及高中低价位房产分布比例——高中低价位房产分布比例——柱状图——公共配置方法----------------------------
function Tiers_Metro_charts(data){
    var myChart = echarts.getInstanceByDom(document.getElementById('Tiers_Metro-chart'));
    if (myChart === undefined) {
        myChart = echarts.init(document.getElementById('Tiers_Metro-chart'));
    }
    //取出数据里的时间
    var dateList = [];
    if(data.bottom != null){
        dateList = data.bottom.map(function(item){
            return item.time;
        });
    }else{
        if(data.middle != null){
            dateList = data.middle.map(function(item){
                return item.time;
            });
        }else{
            if(data.top != null){
                dateList = data.top.map(function(item){
                    return item.time;
                });
            }
        }
    }

    //高价位
    var top_valueList = null;
    if(data.top != null){
        top_valueList = data.top.map(function(item){
            return accounting.formatMoney(item.value * 100, "", 1);
        });
    }
    //中价位
    var middle_valueList = null;
    if(data.middle != null){
        middle_valueList = data.middle.map(function(item){
            return accounting.formatMoney(item.value * 100, "", 1);
        });
    }
    //低价位
    var bottom_valueList = null;
    if(data.bottom != null) {
        bottom_valueList = data.bottom.map(function(item){
            return accounting.formatMoney(item.value * 100, "", 1);
        });
    }

    var option = {
        animation: false,
        title: {
            text: '高中低价位房产分布比例（单位：%）',
            left: 'center'
        },
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            data: ['高价位', '中价位', '低价位'],
            top: 30,
        },
        xAxis: {
            type: 'category',
            data: dateList,
            //坐标轴刻度标签的相关设置
            axisLabel:{
                color: '#969696',
                rotate: '45',
                fontSize: 12
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        yAxis: {
            type: 'value',
            min: 0,
            max: 100,
            //分隔线的相关设置
            splitLine: {
                lineStyle:{
                    color: '#f1f1f1'
                }
            },
            //坐标轴刻度标签的相关设置
            axisLabel: {
                color: '#969696',
                formatter: '{value}%'
            },
            //坐标轴轴线相关设置
            axisLine:{
                lineStyle:{
                    color: '#969696'
                }
            },
            //坐标轴刻度相关设置
            axisTick:{
                show: false,
            },
        },
        series: [
            {
                name: '高价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                stack: '总量',
                label: {
                    show: true,
                },
                data: top_valueList,
            },
            {
                name: '中价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                stack: '总量',
                label: {
                    show: true,
                },
                data: middle_valueList
            },
            {
                name: '低价位',
                type: 'bar',
                barGap: 0,
                barWidth: '40',
                stack: '总量',
                label: {
                    show: true,
                },
                data: bottom_valueList
            }
        ],
        color: ['#003366', '#006699', '#4cabce'],
    };
    myChart.setOption(option);
    window.onresize = myChart.resize;
}

